package com.example.studyinbetterlogin.shapes

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint

class PointShape(startX: Float, startY: Float, mPaint: Paint) : Shape(startX, startY, mPaint) {
    var a: Float = 40f

    override fun isInside(x: Float, y: Float): Boolean {
        return (x - endX) * (x - endX) + (y - endY) * (y - endY) <= a * a
    }

    override fun draw(canvas: Canvas) {
        super.draw(canvas)

        // 绘制圆
        canvas.drawCircle(endX, endY, a, mPaint)

        // 设置文字画笔
        val textPaint = Paint().apply {
            color = Color.BLUE  // 将文字颜色设置为白色
            textSize = a         // 增大文字大小
            textAlign = Paint.Align.CENTER
        }

        // 计算文字的垂直偏移，使文字中心位于圆的上方
        val textYOffset = (textPaint.descent() + textPaint.ascent()) / 2
        val textPadding = 10f  // 设置文字与圆之间的间距
        canvas.drawText(id.toString(), endX, endY - a - textPadding - textYOffset, textPaint)

        canvas.restore()
    }
}
